<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      xmlns:gdmt="">
<head>
    <div th:replace="common/common::html"></div>
    <meta charset="UTF-8">
    <title th:text="#{duty.info.tip}"></title>

    <script th:inline="javascript" >
        var _gridWidth;
        var _gridHeight;
        var leftMenuSetting = {
            check: {
                enable: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback : {
                onClick : onClickNode
            }
        };

        //页面自适应
        function resizePageSize(){
            _gridWidth = $(document).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
            _gridHeight = $(document).height()-32-60; /* -32 顶部主菜单高度，   -90 查询条件高度*/
            $("body").css("height",_gridHeight+"px")
        }
        function leftMenuLoad() {
            $.ajax({
                    type: 'post',
                    async: false,
                    dataType : 'json',
                    url: /*[[@{/ptDuty/getDutyZtreeList}]]*/'',
                    data: [],
                    success: function (data) {
                        $.fn.zTree.init($("#menu-left-tree-ul-id"), leftMenuSetting, data);
                    },
                    error: function(msg){
                        //message(/*[[#{common.error}]]*/'');
                    }
                }
            );
        }
        function onClickNode(event, treeId, treeNode){

        }

        $(function () {
            leftMenuLoad();
            resizePageSize();
            var _columnWidth = _gridWidth/4;
            $("#flexigrid-id").flexigrid({
                width : _gridWidth,
                height : _gridHeight,
                url : /*[[@{getDutyInfolistByPage}]]*/"",
                dataType : 'json',
                colModel : [
                    {display : 'dutyid',name : 'dutyid',width : 150,sortable : false,align : 'center',hide : 'true'},
                    // {display : /*[[#{duty.id}]]*/"",name : 'dutyid',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{duty.name}]]*/"",name : 'name',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{duty.parentName}]]*/"",name : 'organName',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{role.name}]]*/"",name : 'roleName',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{common.operation}]]*/"",name : 'dutyid',width : _columnWidth, sortable : true,align : 'center',process:function (y, _trid, _row) {
                            var htmlContent = '<a href="#" onclick="deleteDuty( \''+ y + '\')"><i class="glyphicon glyphicon-minus" style="color: #2f332a"></i></a>';
                            return htmlContent;
                        }}
                ],
                resizable : false, //resizable table是否可伸缩
                useRp : true,
                usepager : true, //是否分页
                autoload : false, //自动加载，即第一次发起ajax请求
                hideOnSubmit : true, //是否在回调时显示遮盖
                showcheckbox : true, //是否显示多选框
                //rowhandler : rowDbclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                rowbinddata : true

            });
            queryBtn();
            $("#confirm-duty-del-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{duty.delete.tip.titile}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {
                            var dutyid = $("#confirm-duty-del-id").attr("dutyid");
                            $.ajax({
                                type: 'post',
                                async: false,
                                dataType: 'json',
                                url: /*[[@{deleteDutyById}]]*/'',
                                data: [{name: "dutyid", value: dutyid}],
                                success: function (data) {
                                    message(data.msg);
                                    $("#confirm-duty-del-id").dialog( "close" );
                                    queryBtn();
                                },
                                error: function (msg) {
                                    message(/*[[#{common.error}]]*/'');
                                }
                            });

                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    },
                ]
            });

        });//ready
        function queryBtn() {//用户表格的查询
            var searchDutyName = $("#search-duty-name-id").val();
            $("#flexigrid-id").flexOptions({
                extParam:[
                    {name:"searchDutyName",value:searchDutyName}
                ]
            }).flexReload();

        }
        function dutyAdd() {
            let addDutyName = $("#search-duty-name-id").val();
            $.ajax({
                    type: 'post',
                    async: false,
                    dataType : 'json',
                    url: /*[[@{addDuty}]]*/'',
                    data: [
                        {name:"dutyName",value:addDutyName}
                        ],
                    success: function (data) {
                        message(/*[[#{organ.insert.success}]]*/'');
                    },
                    error: function(msg){
                        message(/*[[#{organ.insert.success}]]*/'');
                    }
                }
            );
        }
        function deleteDuty(dutyid) {
            $("#confirm-duty-del-id").attr("dutyid",dutyid);
            $("#confirm-duty-del-id").dialog('open');
        }

    </script>
</head>
<body>
<div>
    <div id="confirm-duty-del-id" style="display: none">
        <span th:text="#{duty.delete.tip.info}"></span>
    </div>
    <div>
        <span th:text="#{duty.info.tip}"></span>
        <a href="#" id="query-btn-id" class="navbar-btn">
            <input type="text" id="search-duty-name-id" th:placeholder="#{duty.name}">
            <i class="glyphicon glyphicon-zoom-in"></i>
            <span th:text="#{common.query}"></span>
        </a>
        <a href="#" id="add-btn-id" class="navbar-btn" onclick="dutyAdd()">
            <i class="glyphicon glyphicon-plus"></i>
            <span th:text="#{common.add}"></span>
        </a>
        <a href="#" id="modify-btn-id" class="navbar-btn">
            <i class="glyphicon glyphicon-wrench"></i>
            <span th:text="#{common.modify}"></span>
        </a>
        <a href="#" id="deletes-btn-id" class="navbar-btn">
            <i class="glyphicon glyphicon-trash"></i>
            <span th:text="#{common.delete}"></span>
        </a>
    </div>

    <table id="flexigrid-id"></table>

</div>
</body>
</html>